<template>
  <div class="Detail">
    <div class="detail-wrapper">
      <div class="header">
        <div class="header-college">
          <div class="overview"><span>{{ reportNum }}</span>人<strong style="padding: 0 10px;">/</strong><span>{{ total }}</span>人</div>
          <h1>{{ college }}</h1>
        </div>
      </div>
      <div class="content">
        <div class="content-title">
          <h1>录取专业</h1>
          <span>{{ majorCount }}</span>
        </div>
        <div class="content-list">
          <div class="card"
            :style="{
              'background-image': `linear-gradient(90deg, #d3c4ff ${ (major.progress * 100) }% , #fff ${( major.progress * 100) }%)`
            }"
            v-for="(major,index) in majorList"
            :key="index"
            @click="goToMajor(major.major)"
          >
            <div class="card-detail">
              <div class="overview"><span>{{ major.reportNum }}</span>人<strong style="padding: 0 10px;">/</strong><span>{{ major.total }}</span>人</div>
              <h1>{{ major.major }}</h1>
            </div>
            <div class="card-progress">
              <span style="font-weight:bold; font-size: 18px;">{{ (major.progress * 100).toFixed(1) }}</span>%
            </div>
          </div>
        </div>
      </div>

    </div>
  </div>
</template>

<script>
import api from '../api/index'

export default {
  name: 'Detail',
  data () {
    return {
      majorList: [],
      majorCount: 0,
      total: 0,
      reportNum: 0,
      studentMajor: ''
    }
  },
  created () {
    window.scroll(0, 0)
    clearInterval(window.timer)
    api.report.getMajorList({ college: this.college }).then(res => {
      if (res.code === 0) {
        this.majorCount = res.data.majorCount
        this.majorList = res.data.majorList
        this.total = this.majorList.map(ele => ele.total).reduce((a, b) => a + b)
        this.reportNum = this.majorList.map(ele => ele.reportNum).reduce((a, b) => a + b)
      }
    })
    api.report.findByStuNo({ stuNo: this.$store.state.userInfo.yb_studentid }).then(res => {
      console.log(res)
      if (res.code === 0) {
        this.studentMajor = res.data['专业']
      }
    })
  },
  methods: {
    goToMajor (major) {
      this.$store.state.major = major
      if (this.studentMajor) {
        if (major === this.studentMajor) {
          this.$router.push('/detail/major')
        } else {
          this.$message.warning('暂未获得该专业详情的权限')
        }
      } else if (this.$store.state.userInfo.yb_employid) {
        this.$router.push('/detail/major')
      } else {
        this.$message.warning('暂未获得该专业详情的权限')
      }
    }
  },
  computed: {
    college () {
      return this.$store.state.userInfo.yb_collegename
    }
  }
}
</script>

<style scoped>
  .Detail {
    width: 100%;
    background: #fff;
    min-height: 100%;
  }

  .detail-wrapper {
    width: 100%;
    padding: 20px 15px;
  }

  .header {
    width: 100%;
  }

  .header-college {
    width: 100%;
    height: 132px;
    display: flex;
    flex-direction: column;
    padding: 30px 15px;
    justify-content: space-between;
    background-image: url('../assets/images/college.png');
    background-size: 100%;
    background-repeat: no-repeat;
    border-radius: 25px;
    box-shadow: 0px 0px 6px 0px rgba(0,0,0,.2);
    color: #fff;
    margin-bottom: 20px;
  }

  .overview span {
    font-size: 1.3em;
    font-weight: bold;
  }

  .header-college h1 {
    font-size: 25px;
    color: #fff;
    font-weight: bold;
    margin: 0;
    text-shadow: 0px 0px 8px rgb(0 0 0 / 20%);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .content-title {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
  }

  .content-title h1 {
    font-size: 26px;
    font-weight: bold;
    color: #333;
    margin: 0;
    padding: 0;
  }

  .content-title span {
    font-size: 12px;
    font-weight: bold;
    margin: 0 10px;
    padding: 2px 6px;
    color: #ff6506;
    background: #ffccaca6;
    border-radius: 5px;
  }

  .card {
    display: flex;
    height: 94px;
    box-shadow: 0px 0px 15px 0px rgba(0,0,0,.1);
    padding: 10px;
    border-radius: 10px;
    margin-bottom: 20px;
    animation: .5s ease-in-out slidein;
  }

  @keyframes slidein {
    from {
      transform: rotate3d(1, 1, -0.5, 50deg);
    }
    to {
      transform: rotate3d(1, 1, 1, 0deg);
    }
  }

  .card .card-detail {
    width: 86%;
  }

  .card .card-detail h1 {
    color: #3f3f3f;
    padding: 0;
    margin: 0;
    font-size: 18px;
    font-weight: bold;
    margin: 10px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
  }

  .card .card-progress {
    flex: 1;
    text-align: center;
    font-size: 14px;
    line-height: 74px;
  }

</style>
